package com.zh.eventdispatch.activity;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.FrameLayout;

/**
 * @author wally
 * @date 2021/06/05
 * 接收Activity事件的FrameLayout
 */
public class ActivityEventFrameLayout extends FrameLayout implements ActivityEventView {
    private final ActivityEventHelper mHelper;

    public ActivityEventFrameLayout(Context context) {
        this(context, null);
    }

    public ActivityEventFrameLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ActivityEventFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mHelper = new ActivityEventHelper(context, this);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mHelper.onAttachedToWindow();
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mHelper.onDetachedFromWindow();
    }

    @Override
    public boolean onSupportActivityResult(int requestCode, int resultCode, Intent data) {
        return mHelper.getEventDispatcher().dispatchOnActivityResult(requestCode, resultCode, data);
    }

    @Override
    public boolean onSupportBackPressed() {
        return mHelper.getEventDispatcher().dispatchOnBackPressed();
    }

    @Override
    public ActivityEventDispatcher getEventDispatcher() {
        return mHelper.getEventDispatcher();
    }
}